// 主入口文件
let express = require("express");
let app = express();

let expressJWT = require("express-jwt")
app.listen(3000, function () {
    console.log(3000);
});
// token 解密 如果是正确
app.use(expressJWT({
    secret: 'token130', // 解密字符串，要和加密的secret一样
    algorithms: ['HS256']
}).unless({
    // 除了登录和注册的接口之外，其他接口都需要认证
    path: ['/api/login', '/api/reguser']
}));

// 处理post请求解析的问题
app.use(express.urlencoded({
    extended: false
}));



let category = require("./routers/category");
app.use("/my/article", category)

// 登录
let login = require("./routers/login");
app.use("/api", login)

// 用户信息
let user = require("./routers/user");
app.use("/my", user)

//
let article = require("./routers/article");
app.use("/my/article", article)

app.use(function (err, req, res, next) {
    console.log(err);
    if (err.code == "invalid_token") {
        res.send({
            "status": 1,
            "message": "身份验证失败！",
        })
    }
})